package com.cmc.impl.hr;


import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import com.cmc.service.merchant.model.MerchantEntry;
import com.cmc.service.merchant.service.persistence.MerchantEntryUtil;
import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class HrAdminPortlet extends MVCPortlet {
	
	public void merchantActions(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
		
		String cmd = ParamUtil.getString(actionRequest, "merchantId");
		
		try {
			MerchantEntry merchant = null;
			
			if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
				merchant = MerchantEntryUtil.create(0);
			} else if (cmd.equals(Constants.DELETE)) {
				
			}
			
			String redirect = ParamUtil.getString(actionRequest, "redirect");
			
			if (merchant != null) {
				redirect = HttpUtil.setParameter(redirect,actionResponse.getNamespace() + "merchantId", merchant.getMerchantId());
			}
			
			actionResponse.sendRedirect(redirect);			
		} catch (Exception e) {
			throw e;
		}		
	}
	
	private MerchantEntry updateMerchant(ActionRequest actionRequest) {
		
		long merchantId = ParamUtil.getLong(actionRequest, "merchantId");
		
		MerchantEntry merchant = null;
		
		if (merchantId <= 0) {
			// Add Merchant
			//merchant = MerchantEntryLocalServiceUtil.addMerchant(userId, merchantEntry, serviceContext);
		} else {
			// Update merchant
		}
		
		return merchant;
	}
}
